<?php
// +----------------------------------------------------------------------
// | 菜单管理控制器
// +----------------------------------------------------------------------
// | Author: myh
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\admin\service\SysMenuService;


class SysMenu extends AdminController
{
    //新增
    public function add(){
        $data = $this->request->post();
        //验证规则
        $validate = [
            'name' => 'require'
        ];
        //提示信息
        $message = [
            'name.require' => '名称不能为空!'
        ];
        $this->validate($data, $validate, $message);
        
        return SysMenuService::save($data);
    }

    //更新
    public function edit(){
        $data = $this->request->post();
        //验证规则
        $validate = [
            'id' => 'require',
            'name' => 'require'
        ];
        //提示信息
        $message = [
            'id.require' => 'ID不能为空!',
            'name.require' => '名称不能为空!'
        ];

        $this->validate($data, $validate, $message);

        return SysMenuService::update($data);
    }

    //列表
    public function list(){
        return SysMenuService::list();
    }

    //删除
    public function delete(){
        $ids = $this->request->get("ids");
        if(empty($ids)){
            return failure(config('error.er5')['code'],"请选择要删除的数据");
        }

        return SysMenuService::destroy($ids);
    }

}
